package leetcodev1.树;

import java.util.Stack;

public class LeetCode173 {


}

class BSTIterator {
    TreeNode curr;
    Stack<TreeNode> stack;

    //在构造函数构造一个list，通过list不断迭代极客
    public BSTIterator(TreeNode root) {
        curr = root;
        this.stack = new Stack<>();
    }

    public int next() {
        while (curr != null) {
            this.stack.push(curr);
            curr = curr.left;
        }
        TreeNode pop = this.stack.pop();
        curr = pop.right;
        return pop.val;
    }

    public boolean hasNext() {
        return !this.stack.isEmpty() || curr != null;
    }
}
